package mo.leetcode_hot;

import java.util.Stack;

public class L155 {

    private final Stack<Integer> stack = new Stack<>();
    private final Stack<Integer> min = new Stack<>();

    public L155() {

    }

    public void push(int val) {
        stack.push(val);
        if (min.isEmpty() || val < min.peek()) {
            min.push(val);
        } else {
            min.push(min.peek());
        }
    }

    public void pop() {
        if (!stack.isEmpty()) {
            stack.pop();
            min.pop();
        }


    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return min.peek();
    }

}
